package com.gitee.wsl.compose.ui.swiperefresh.classic


/**
 * 经典样式的指示器
 *
 * @author <a href="mailto:jenly1314@gmail.com">Jenly</a>
 * <p>
 * <a href="https://github.com/jenly1314">Follow me</a>
 */
/*@Composable
internal fun ClassicRefreshIndicator(
    state: UltraSwipeRefreshState,
    isFooter: Boolean,
    tipContent: String,
    tipTime: String,
    modifier: Modifier = Modifier,
    tipContentStyle: TextStyle = TextStyle.Default.copy(
        fontSize = 15.sp,
        color = Color(0xFF666666)
    ),
    tipTimeStyle: TextStyle = TextStyle.Default.copy(
        fontSize = 12.sp,
        color = Color(0xFF999999)
    ),
    tipTimeVisible: Boolean = true,
    paddingValues: PaddingValues = PaddingValues(12.dp),
    arrowIconPainter: Painter = painterResource(id = R.drawable.usr_classic_arrow),
    loadingIconPainter: Painter = painterResource(id = R.drawable.usr_classic_refreshing),
    iconSize: Dp = 24.dp,
    iconColorFilter: ColorFilter? = null,
    label: String = "Indicator"
) {
    val arrowDegrees = remember { Animatable(0f) }

    if (isFooter) {
        LaunchedEffect(state.footerState) {
            when (state.footerState) {
                UltraSwipeFooterState.ReleaseToLoad -> {
                    arrowDegrees.animateTo(0f)
                }

                else -> arrowDegrees.animateTo(180f)
            }
        }
    } else {
        LaunchedEffect(state.headerState) {
            when (state.headerState) {
                UltraSwipeHeaderState.ReleaseToRefresh -> {
                    arrowDegrees.animateTo(180f)
                }

                else -> arrowDegrees.animateTo(0f)
            }
        }
    }

    val alphaState = remember {
        derivedStateOf {
            if ((!isFooter && state.indicatorOffset > 0f) || (isFooter && state.indicatorOffset < 0f)) {
                1f
            } else {
                0f
            }
        }
    }

    Box(
        modifier = modifier
            .fillMaxWidth()
            .padding(paddingValues),
        contentAlignment = Alignment.Center
    ) {
        Row(
            modifier = Modifier.alpha(alphaState.value),
            verticalAlignment = Alignment.CenterVertically
        ) {
            if (if (isFooter) state.isLoading else state.isRefreshing) {
                val transition = rememberInfiniteTransition(label)
                val rotate by transition.animateFloat(
                    initialValue = 0f,
                    targetValue = 360f,
                    animationSpec = infiniteRepeatable(
                        animation = tween(
                            durationMillis = 1000,
                            easing = LinearEasing
                        )
                    ),
                    label = label
                )
                Image(
                    painter = loadingIconPainter,
                    contentDescription = null,
                    modifier = Modifier
                        .size(iconSize)
                        .rotate(rotate),
                    colorFilter = iconColorFilter,
                )

            } else {
                Image(
                    painter = arrowIconPainter,
                    contentDescription = null,
                    modifier = Modifier
                        .size(iconSize)
                        .rotate(arrowDegrees.value),
                    colorFilter = iconColorFilter,
                )
            }
            Column(
                modifier = Modifier.padding(horizontal = 6.dp),
                verticalArrangement = Arrangement.Center
            ) {
                BasicText(
                    text = tipContent,
                    style = tipContentStyle,
                )
                if (tipTimeVisible) {
                    Spacer(modifier = Modifier.size(2.dp))
                    BasicText(
                        text = tipTime,
                        style = tipTimeStyle,
                    )
                }
            }
        }
    }
}*/
